package com.ledi.guns.modular.ledipay.controller;

import io.swagger.annotations.Api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ledi.guns.common.annotion.Permission;
import com.ledi.guns.core.base.controller.BaseController;
import com.ledi.guns.core.base.tips.SuccessTip;
import com.ledi.guns.core.base.tips.Tip;
import com.ledi.guns.modular.ledipay.controller.req.clazz.ClassAdd.Update;
import com.ledi.guns.modular.ledipay.controller.req.staff.AddStaffInfo;
import com.ledi.guns.modular.ledipay.service.impl.StaffServiceImpl;

@Api
@RestController
@RequestMapping("/staff")
public class StaffController extends BaseController {

	@Autowired
	private StaffServiceImpl staffService;

	/**
	 * @api {POST} /staff/addStaffInfo 增加员工
	 * @apiGroup staff
	 * @apiName addStaffInfo
	 * @apiParam {String} account 账号
	 * @apiParam {String} name 名称
	 * @apiParam {String} password 密码
	 * @apiParam {String} roleName 角色
	 * @apiVersion 1.0.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "account": "xiaosi",
	 *                  "name": "小四",
	 *                  "password": "123456",
	 *                  "roleName": "超级管理员"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	@Permission
	@RequestMapping(value = "/addStaffInfo", method = RequestMethod.POST)
	public Tip add(@RequestBody AddStaffInfo addStaffInfo) {

		staffService.addStaffInfo(addStaffInfo);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {PUT} /staff/mergeStaffInfo 编辑员工
	 * @apiGroup staff
	 * @apiName mergeStaffInfo
	 * @apiParam {String} name 名称
	 * @apiParam {String} password 密码
	 * @apiParam {String} roleName 角色
	 * @apiVersion 1.5.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "name": "小四",
	 *                  "password": "123456",
	 *                  "roleName": "超级管理员"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	// @Permission
	@RequestMapping(value = "/mergeStaffInfo", method = RequestMethod.PUT)
	public Tip merge(@RequestBody @Validated(Update.class) AddStaffInfo addStaffInfo) {

		staffService.editStaffInfo(addStaffInfo);
		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {DELETE} /staff/deleteStaff/{id} 删除员工用户
	 * @apiGroup staff
	 * @apiName deleteStaff
	 * @apiParam id 用户id
	 * @apiSuccess code 返回编码（200成功）
	 * @apiSuccess message 返回说明
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 * @apiVersion 1.1.0
	 */
	@RequestMapping(value = "/deleteStaff/{id}", method = RequestMethod.DELETE)
	// @Permission
	public Tip deleteStaff(@PathVariable Integer id) {

		staffService.deleteStaff(id);
		return SuccessTip.buildSuccess();
	}

}
